package com.cssw.fyzb.busi.api.user;

import com.cssw.fyzb.busi.convert.Converter;
import com.cssw.fyzb.busi.service.user.UserRelService;
import com.cssw.fyzb.busi.service.user.UserService;
import com.cssw.fyzb.core.model.dodb.AvatarPendantDef;
import com.cssw.fyzb.core.model.dodb.User;
import com.cssw.fyzb.core.model.vo.user.AvatarPendantDefVo;
import com.cssw.fyzb.core.model.vo.user.PublicUserInfoVo;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.*;
import com.ydn.dbframe.plugin.activerecord.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 挂件列表
 *
 * @author YangYiQun
 */
@Function(description = "挂件列表", parameters = {
        @Parameter(name = "userId", type = Type.Integer, description = "用户标识", required = true),
})
@Component
public class ListAvatarPendantDef implements Action {

    @Autowired
    private UserService userService;

    private static final Logger logger = LoggerFactory.getLogger(ListFans.class);

    @Override
    public Response execute(Request request) throws Exception {
        Long userId = request.getLong("userId");
        try {
            List<AvatarPendantDef> pendantDefList = userService.listAvatarPendantDef();

            List<AvatarPendantDefVo> list = ((Converter<List<AvatarPendantDef>, List<AvatarPendantDefVo>>) pendantDefs -> {
                List<AvatarPendantDefVo> vos = new ArrayList<>();
                pendantDefs.forEach((v) -> {
                    AvatarPendantDefVo vo = new AvatarPendantDefVo();
                    vo.setPendantId(v.getPendantId());
                    vo.setPendantName(v.getPendantName());
                    vo.setPendantUrl(v.getPendantUrl());

                    vos.add(vo);
                });
                return vos;
            }).convert(pendantDefList);
            return Response.success().put("list", list).put("count", pendantDefList.size());
        } catch (Exception e) {
            logger.info("", e);
            return Response.fail("操作异常");
        }
    }

}
